<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        
        // function fun (name,age,sex ){
        //     var obj = new Object();
        //     obj.name = name;
        //     obj.age = age;
        //     obj.sex = sex;
        //     obj.sayName=function () {
        //         console.log(this.age);
        //     };
            
        //     return obj
        // }
        // var obj1 = fun("张三",18,"男");
        // var obj2 = fun ("李四",10,"女");
        
        // console.log(obj1.name);
        // console.log(this.obj2);

        // //调用sayName函数
        // obj1.sayName();
        // //打印sayName对象
        // console.log(obj1.sayName);
        

        //-------------------------------------------------------------------------------------
        
        //另一种创建
        // function createcar(name,color,zhonglei) {
        //     var obj = {
        //         name:name,
        //         color:color,
        //         zhonglei:zhonglei
        //     }
        //     return obj;
        // }

        // var obj3 = createcar("大众","白色","汽车");
        // console.log(obj3);

        //--------------------------------------------------------------------------------------

        function Person(name,age,sex ){
            var obj = new Object();
            this.name = name;
            this.age = age;
            this.sex = sex;
            this.sayName=function () {
                console.log(this.age);
            };

        }
        var person1 = new Person("王五",18,"男");
        var person2 = new Person("小红",10,"女");
        
        console.log(person1.name);
        console.log(this.person2);
        console.log(person1);

        /*
            使用instanceof 可以检查一个对象是否是一个类的实例
            语法：对象 instanceof 构造函数
            如果是，返回ture；如果不说返回false
            
            注意：所有的对象都是Object的后代，故检查时都会返回ture
        */  
        console.log(person1 instanceof Person);

    </script>
</body>
</html>